package com.wind.taobao.api.trade.shop.convert
{
	import com.wind.taobao.api.trade.shop.model.TaobaoShop;
	import com.wind.taobao.core.util.TaobaoConstants;
	
	import mx.collections.ArrayCollection;


	/**
	 * Shop转换器
	 * @author fxy
	 *
	 */
	public class ShopConvert
	{
		/**
		 * 转换Shop集合
		 */
		public static function convertShops(value:Object, type:String="json"):ArrayCollection
		{
			var shops:ArrayCollection=new ArrayCollection();
			if (value != null)
			{
				if (type == TaobaoConstants.JSON)
				{
					if ((value as Array).length > 0)
					{
						for (var i:uint=0; i < (value as Array).length; i++)
						{
							shops.addItem(convertShop((value as Array)[i]));
						}
					}
				}
				else
				{
					//TODO
				}
			}
			return shops;
		}

		/**
		 * 转换Shop
		 */
		public static function convertShop(value:Object, type:String="json"):TaobaoShop
		{
			var shop:TaobaoShop=new TaobaoShop();
			if (value == null)
				return shop;
			if (type == TaobaoConstants.XML)
			{
				shop=convertXMLToShop(XML(value), shop);
			}
			else
			{
				shop=convertJSONToShop(value, shop);
			}
			return shop;
		}

		/**
		 * JSON转换为Shop
		 */
		private static function convertJSONToShop(json:Object, shop:TaobaoShop):TaobaoShop
		{
			if (json.hasOwnProperty(TaobaoConstants.SID))
			{
				shop.sid=json[TaobaoConstants.SID];
			}
			if (json.hasOwnProperty(TaobaoConstants.CID))
			{
				shop.cid=json[TaobaoConstants.CID];
			}
			if (json.hasOwnProperty(TaobaoConstants.NICK))
			{
				shop.nick=json[TaobaoConstants.NICK];
			}
			if (json.hasOwnProperty(TaobaoConstants.TITLE))
			{
				shop.title=json[TaobaoConstants.TITLE];
			}
			if (json.hasOwnProperty(TaobaoConstants.DESC))
			{
				shop.desc=json[TaobaoConstants.DESC];
			}
			if (json.hasOwnProperty(TaobaoConstants.BULLETIN))
			{
				shop.bulletin=json[TaobaoConstants.BULLETIN];
			}
			if (json.hasOwnProperty(TaobaoConstants.PIC_PATH))
			{
				shop.pic_path=json[TaobaoConstants.PIC_PATH];
			}
			if (json.hasOwnProperty(TaobaoConstants.CREATED))
			{
				shop.created=json[TaobaoConstants.CREATED];
			}
			if (json.hasOwnProperty(TaobaoConstants.MODIFIED))
			{
				shop.modified=json[TaobaoConstants.MODIFIED];
			}
			return shop;
		}

		/**
		 * XML转换为Shop
		 */
		private static function convertXMLToShop(value:XML, shop:TaobaoShop):TaobaoShop
		{
			return shop;
		}


	}
}